import _kqueue as _
from constants import *

# change the namespaces
Event = _.Event

def kqueue():
    '''Wrap kqueue system call.
>>> import kqueue
>>> kq = kqueue()
>>> if kq > -1: print kq
    '''
    return _.kqueue()

def kevent(kq, changelist, nchanges, nevents, timeout):
    '''Wrap kevent sytem call.
    Changes that should be applied to the kqueue
    are given in the changelist, and any returned events are
    placed in the eventlist, up to the maximum size allowed
    by nevents. The number of entries actually placed in the
    eventlist is returned by the kevent() call.
    >>> import sys
    >>> import kqueue
    >>> kq = kqueue()
    >>> e = Event(sys.stdin.fileno(), kqueue.EVFILT_READ, kqueue.EV_ADD)
    >>> kevent(kq, [e], 1, 1, None)
    '''
    return _.kevent(kq, changelist, nchanges, nevents, timeout)